package com.mht.book.controller;


import com.mht.book.entity.book.BookList;
import com.mht.book.entity.user.AdminUser;
import com.mht.book.entity.user.NormalUser;
import com.mht.book.entity.user.User;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;

/**
 * @author wangfusheng
 * @version 1.0.0
 * @ClassName NewLogin.java
 * @Description TODO
 * @createTime 2022/12/417:10
 */
public class NewLogin {

    //访问用户的白名单，只有在白名单中的账号才可以访问本系统
   public static Map<String , User> initUser(){
       Map<String ,User> users = new HashMap<>();
       User user = new AdminUser("zhangsan");
       User user2 = new NormalUser("lisi");
       users.put("zhangsan",user);
       users.put("lisi",user2);
       return users;
    }

    public static void main(String[] args) {
        BookList bookList = new BookList();
        Map<String ,User> users = initUser();
        System.out.println("请输入您的姓名：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        User user = users.get(name);
        if(Objects.isNull(user)){
            System.out.println("您无权访问本系统");
            System.out.println("请注册用户：->   1.注册； 2.退出");
            int choice = sc.nextInt();
            if(1 == choice){
                User user1 = new NormalUser(name);
                users.put(name,user1);
                System.out.println("恭喜您，注册成功！");
                user = user1;
            }else {
                System.exit(0);
            }
        }
        while (true){
            int choice = user.menu();
            user.doOperation(bookList,choice-1);
        }
    }

}
